Skip to content

Issue #1285 grid data from imod5#1286

Merged
JoerivanEngelen merged 10 commits into
issue_#1260_from_imod5_data_metaswapfrom
issue_#1285_GridData_from_imod5
Nov 14, 2024
Merged

Issue #1285 grid data from imod5#1286
JoerivanEngelen merged 10 commits into
issue_#1260_from_imod5_data_metaswapfrom
issue_#1285_GridData_from_imod5

Conversation

@JoerivanEngelen

@JoerivanEngelen JoerivanEngelen commented Nov 11, 2024

Copy link
Copy Markdown
Contributor

Fixes #1285

Description

  • This PR implements GridData.from_imod5_data, which has the following requirements:
    • Area: Split area in rural & urban area
    • Active: Split where active/inactive
    • Landuse: Set urban_landuse to 18
    • Rootzone thickness: convert from centimeter to meter
  • Refactors the test_grid_data.py to separate cases, reduces code duplication
  • Add unittest for GridData.from_imod5_data

It has a arguments for regridding, but these don't do anything yet. I wasn't sure if I should keep this to already have a future-proof signature, or not add these, as the regridder arguments only confuse people. I don't think regridding the MetaSWAP iMOD5 grids (like we do with MODFLOW6 data) is a part of iMOD Python now, as we are first focusing on the LHM, for which this is not a hard requirement.

Checklist

  • Links to correct issue
  • Update changelog, if changes affect users
  • PR title starts with Issue #nr, e.g. Issue #737
  • Unit tests were added
  • If feature added: Added/extended example

@JoerivanEngelen JoerivanEngelen marked this pull request as ready for review November 13, 2024 16:18
Comment thread imod/msw/grid_data.py Outdated
data["area"] = get_cell_area_from_imod5_data(imod5_data)
data["landuse"] = get_landuse_from_imod5_data(imod5_data)
data["rootzone_depth"] = get_rootzone_depth_from_imod5_data(imod5_data)
data["surface_elevation"] = imod5_data["cap"]["surface_elevation"]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does "cap" stand for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "CAP" package in iMOD5, which I think refers to the "capillary zone".

Comment thread imod/msw/grid_data.py Outdated
@classmethod
def from_imod5_data(
cls,
imod5_data: dict[str, dict[str, GridDataArray]],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like they only thing we are using from imod5_data is the cap entry.
You could have this method accept only that entry

from_imod_data(data["cap"] ,...)

If thats not convienient for the user you could declare a local variable to hold it and pass only that to the other internal methods:

imod5_cap = imod5_data["cap"]
data = {}
data["area"] = get_cell_area_from_imod5_data(imod5_cap )
data["landuse"] = get_landuse_from_imod5_data(imod5_cap )
data["rootzone_depth"] = get_rootzone_depth_from_imod5_data(imod5_cap )
data["surface_elevation"] = imod5_cap["surface_elevation"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, done!

Comment thread imod/msw/grid_data.py Outdated


def get_cell_area_from_imod5_data(
imod5_data: dict[str, dict[str, GridDataArray]],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The structure dict[str, GridDataArray] is something we use a lot. We could create a type alias to make working with it easier and also make it clearer from the type name what it is.
I was thinking about naming it something like

GridDataSet = dict[str, GridDataArray]
or
GridDataCollection = dict[str, GridDataArray]

@JoerivanEngelen JoerivanEngelen Nov 14, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, GridDataset is already taken for:

GridDataset: TypeAlias = Union[xr.Dataset, xu.UgridDataset]

I named a type alias: GridDataDict.

Comment thread imod/msw/grid_data.py
imod5_data: dict[str, dict[str, GridDataArray]],
) -> GridDataArray:
rural_landuse = imod5_data["cap"]["landuse"]
# Urban landuse = 18

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this mean?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iMOD5 supports having two landuses per grid cell (so two "subunits" in iMOD Python lingo), the first one is for rural landuse, the second for urban landuse. The first one is specified by a rural landuse grid, and can thus have different values (e.g. agriculture, forestry, cattle), the second one is always landuse "urban", which is specified with the number 18.

I will explain some more in docstring.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
13.2% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@JoerivanEngelen

Copy link
Copy Markdown
Contributor Author

Tests fail due to an issue with a single TeamCity agent, merging to feature branch.

@JoerivanEngelen JoerivanEngelen merged commit 6918786 into issue_#1260_from_imod5_data_metaswap Nov 14, 2024
@JoerivanEngelen JoerivanEngelen deleted the issue_#1285_GridData_from_imod5 branch November 14, 2024 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants